"""Definition of the eventfolder content type
"""

from zope.interface import implements
from Products.CMFCore.utils import getToolByName

from Products.ATContentTypes.content import folder
from Products.ATContentTypes.content import schemata

# -*- Message Factory Imported Here -*-

from my315ok.researchevent.interfaces import Ieventfolder
from my315ok.researchevent.config import PROJECTNAME

try:
    from Products.LinguaPlone import public as atp
except ImportError:
    # No multilingual support
    from Products.Archetypes import atapi as atp

eventfolderSchema = folder.ATFolderSchema.copy() + atp.Schema((

    # -*- Your Archetypes field definitions here ... -*-

))

# Set storage on fields copied from ATFolderSchema, making sure
# they work well with the python bridge properties.

eventfolderSchema['title'].storage = atp.AnnotationStorage()
eventfolderSchema['description'].storage = atp.AnnotationStorage()

schemata.finalizeATCTSchema(
    eventfolderSchema,
    folderish=True,
    moveDiscussion=False
)


class eventfolder(folder.ATFolder):
    """A contains research events folder"""
    implements(Ieventfolder)

    meta_type = "eventfolder"
    schema = eventfolderSchema
    
    def initializeArchetype(self,**kwargs):
        try:
            self.initializeLayers()
            self.markCreationFlag()
            self.setDefaults()
            if kwargs:
                self.edit(**kwargs)
            self._signature = self.Schema().signature()
            if self.isPrincipiaFolderish:
                self.copyLayoutFromParent()
        except ConflictError:
            raise
        except Exception, msg:
            LOG.warn('Exception in initializeArchetype', exc_info=True)
            if DEBUG and str(msg) not in ('SESSION',):
                # debug code
                raise        
        # Enable  syndication by default
        syn_tool = getToolByName(self, 'portal_syndication', None)
        if syn_tool is not None:
            if (syn_tool.isSiteSyndicationAllowed() and
                                    not syn_tool.isSyndicationAllowed(self)):
                syn_tool.enableSyndication(self)
        return 

    title = atp.ATFieldProperty('title')
    description = atp.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-

atp.registerType(eventfolder, PROJECTNAME)
